package com.ruoyi.chiwen.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.chiwen.domain.TbStaging;
import com.ruoyi.chiwen.service.ITbStagingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 应还金额Controller
 * 
 * @author chiwen
 * @date 2021-06-14
 */
@RestController
@RequestMapping("/chiwen/staging")
public class TbStagingController extends BaseController
{
    @Autowired
    private ITbStagingService tbStagingService;

    /**
     * 查询应还金额列表
     */
    @PreAuthorize("@ss.hasPermi('chiwen:staging:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbStaging tbStaging)
    {
        startPage();
        List<TbStaging> list = tbStagingService.selectTbStagingList(tbStaging);
        return getDataTable(list);
    }

    /**
     * 导出应还金额列表
     */
    @PreAuthorize("@ss.hasPermi('chiwen:staging:export')")
    @Log(title = "应还金额", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbStaging tbStaging)
    {
        List<TbStaging> list = tbStagingService.selectTbStagingList(tbStaging);
        ExcelUtil<TbStaging> util = new ExcelUtil<TbStaging>(TbStaging.class);
        return util.exportExcel(list, "应还金额数据");
    }

    /**
     * 获取应还金额详细信息
     */
    @PreAuthorize("@ss.hasPermi('chiwen:staging:query')")
    @GetMapping(value = "/{tId}")
    public AjaxResult getInfo(@PathVariable("tId") Long tId)
    {
        return AjaxResult.success(tbStagingService.selectTbStagingById(tId));
    }

    /**
     * 新增应还金额
     */
    @PreAuthorize("@ss.hasPermi('chiwen:staging:add')")
    @Log(title = "应还金额", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbStaging tbStaging)
    {
        return toAjax(tbStagingService.insertTbStaging(tbStaging));
    }

    /**
     * 修改应还金额
     */
    @PreAuthorize("@ss.hasPermi('chiwen:staging:edit')")
    @Log(title = "应还金额", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbStaging tbStaging)
    {
        return toAjax(tbStagingService.updateTbStaging(tbStaging));
    }

    /**
     * 删除应还金额
     */
    @PreAuthorize("@ss.hasPermi('chiwen:staging:remove')")
    @Log(title = "应还金额", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tIds}")
    public AjaxResult remove(@PathVariable Long[] tIds)
    {
        return toAjax(tbStagingService.deleteTbStagingByIds(tIds));
    }
}
